package com.qire.manhua.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;

import com.qire.common.support.base.BaseDialog;
import com.qire.manhua.R;
import com.qire.manhua.databinding.DialogBuyResultTipsBinding;

import java.util.Locale;

import androidx.annotation.NonNull;

/**
 * 支付成功提示框：在购买金币市场、购买VIP等页面支付成功后显示
 */
public class BuyResultTipsDialog extends BaseDialog {

    public enum PayTipType {
        Recharge("充值成功", R.drawable.app_buy_result_icon_coin),
        Membership("开通成功", R.drawable.app_buy_result_icon_member);
        PayTipType(String title, int resID){
            this.title = title;
            this.resID = resID;
        }
        final String title;
        final int resID;
    }

    private PayTipType payTipType;

    private int orderCoin = 0, awardBean = 0;

    private String membershipDays = "";

    private DialogBuyResultTipsBinding viewDataBinder;
    private final String format_tips = "本次充值获得%d金币\n并获赠%d金豆";

    public BuyResultTipsDialog(@NonNull Context context, PayTipType payTipType) {
        super(context, R.style.CustomDialog);
        this.payTipType = payTipType;
    }

    public BuyResultTipsDialog setWare(int orderCoin, int awardBean) {
        this.orderCoin = orderCoin;
        this.awardBean = awardBean;
        return this;
    }

    public BuyResultTipsDialog setMembershipDays(String membershipDays){
        this.membershipDays = membershipDays;
        return this;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        initView();
    }

    private void initView() {
        viewDataBinder = DialogBuyResultTipsBinding.inflate(LayoutInflater.from(this.getContext()));
        setContentView(viewDataBinder.getRoot());
        viewDataBinder.close.setOnClickListener(v -> dismiss());

        viewDataBinder.icon.setImageResource(payTipType.resID);
        viewDataBinder.title.setText(payTipType.title);

        switch (payTipType) {
            case Recharge:
                viewDataBinder.textTips.setText(String.format(Locale.getDefault(), format_tips, orderCoin, awardBean));
                break;
            case Membership: {
                String content = "恭喜您，获得" + membershipDays + "特权";
                viewDataBinder.textTips.setText(content);
                break;
            }
        }
    }
}
